﻿using System.Collections;
using System.Data;
using System.Text;

namespace BISTools.DBTools
{
    /// <summary>
    /// 数据库通用操作层接口
    /// 版本：2.0
    /// </summary>
    public interface IDbHelper
    {
        #region 根据SQL返回影响行数

        /// <summary>
        /// 根据SQL返回影响行数
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <returns></returns>
        object GetObjectValue(StringBuilder sql);

        /// <summary>
        /// 根据SQL返回影响行数,带参数
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        object GetObjectValue(StringBuilder sql, SqlParam[] param);

        #endregion 根据SQL返回影响行数

        #region 根据SQL执行

        /// <summary>
        /// 根据SQL执行
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <returns></returns>
        int ExecuteBySql(StringBuilder sql);

        /// <summary>
        /// 根据SQL执行,带参数
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        int ExecuteBySql(StringBuilder sql, SqlParam[] param);

        /// <summary>
        /// 批量执行sql语句,带参数
        /// </summary>
        /// <param name="sqls">SQL</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        int BatchExecuteBySql(StringBuilder[] sql, object[] param);

        object GetSingle(StringBuilder sql, SqlParam[] param);

        #endregion 根据SQL执行

        #region 根据 SQL 返回 DataTable

        /// <summary>
        /// 获取数据集，没有条件
        /// </summary>
        /// <param name="TargetTable">目标表名</param>
        /// <returns>DataTable</returns>
        DataTable GetDataTable(string TargetTable);

        /// <summary>
        /// 获取数据集,排序
        /// </summary>
        /// <param name="TargetTable">目标表名</param>
        /// <param name="orderField">排序字段</param>
        /// <param name="orderType">排序类型</param>
        /// <returns></returns>
        DataTable GetDataTable(string TargetTable, string orderField, string orderType);

        /// <summary>
        /// 根据 SQL 返回 DataTable
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <returns></returns>
        DataTable GetDataTableBySQL(StringBuilder sql);

        /// <summary>
        /// 根据 SQL 返回 DataTable,带参数
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        DataTable GetDataTableBySQL(StringBuilder sql, SqlParam[] param);

        /// <summary>
        /// 摘要:
        ///     执行一存储过程DataTable
        /// 参数：
        ///     procName：存储过程名称
        ///     Hashtable：传入参数字段名
        /// </summary>
        DataTable GetDataTableProc(string procName, Hashtable ht);

        /// <summary>
        /// 摘要:
        ///     执行一存储过程DataTable 返回多个值
        /// 参数：
        ///     procName：存储过程名称
        ///     Hashtable：传入参数字段名
        ///     rs       :返回值
        /// </summary>
        DataTable GetDataTableProcReturn(string procName, Hashtable ht, ref Hashtable rs);

        #endregion 根据 SQL 返回 DataTable

        #region 根据 SQL 返回 DataSet

        /// <summary>
        /// 根据 SQL 返回 DataSet
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns>DataSet</returns>
        DataSet GetDataSetBySQL(StringBuilder sql);

        /// <summary>
        /// 根据 SQL 返回 DataSet
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns>DataSet</returns>
        DataSet GetDataSetBySQL(string sql);

        /// <summary>
        /// 根据 SQL 返回 DataSet
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        DataSet GetDataSetBySQL(StringBuilder sql, SqlParam[] param);

        #endregion 根据 SQL 返回 DataSet

        #region 根据 SQL 返回 IList

        /// <summary>
        /// 根据 SQL 返回 IList
        /// </summary>
        /// <typeparam name="T">实体类</typeparam>
        /// <param name="sql">语句</param>
        /// <returns></returns>
        IList GetDataListBySQL<T>(StringBuilder sql);

        /// <summary>
        /// 根据 SQL 返回 IList,带参数 (比DataSet效率高)
        /// </summary>
        /// <typeparam name="T">实体类</typeparam>
        /// <param name="sql">Sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        IList GetDataListBySQL<T>(StringBuilder sql, SqlParam[] param);

        #endregion 根据 SQL 返回 IList

        #region 存储过程

        /// <summary>
        /// 摘要:
        ///     执行一存储过程返回标识
        /// 参数：
        ///     procName：存储过程名称
        ///     Hashtable：传入参数字段名
        /// </summary>
        int ExecuteByProc(string procName, Hashtable ht);

        /// <summary>
        /// 执行一存储过程返回标识(不带事务)
        /// </summary>
        int ExecuteByProcNotTran(string procName, Hashtable ht);

        /// <summary>
        /// 执行存储过程返回指定消息
        /// </summary>
        int ExecuteByProcReturnMsg(string procName, Hashtable ht, ref object rs);

        /// <summary>
        /// 执行存储过程返回多个值
        /// </summary>
        int ExecuteByProcReturn(string procName, Hashtable intputHt, ref Hashtable outputHt);

        /// <summary>
        /// 根据存储过程返回数据集
        /// </summary>
        /// <param name="procName"></param>
        /// <returns></returns>
        DataSet ExcuteProc(string procName);

        /// <summary>
        /// 增加参数化的存储过程
        /// </summary>
        /// <param name="procName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        DataSet ExcuteProc(string procName, SqlParam[] param);

        /// <summary>
        /// 增加参数化的存储过程
        /// </summary>
        /// <param name="procName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        int ExcuteProc(string procName, SqlParam[] param, string NULL);

        #endregion 存储过程

        #region 数据分页

        /// <summary>
        /// 摘要:
        ///     数据分页接口
        /// 参数：
        ///     sql：传入要执行sql语句
        ///     param：参数化
        ///     orderField：排序字段
        ///     orderType：排序类型
        ///     pageIndex：当前页
        ///     pageSize：页大小
        ///     count：返回查询条数
        /// </summary>
        DataTable GetPageList(string sql, SqlParam[] param, string orderField, string orderType, int pageIndex, int pageSize, ref int count);

        #endregion 数据分页

        #region SqlBulkCopy 批量导入数据库

        /// <summary>
        /// 利用Net SqlBulkCopyImport 批量导入数据库,速度超快
        /// </summary>
        /// <param name="dt">源内存数据表</param>
        /// <returns></returns>
        bool SqlBulkCopyImport(DataTable dt);

        #endregion SqlBulkCopy 批量导入数据库

        DataSet ExecuteDataset(bool InTransaction, CommandType commandType, string commandText, params IDataParameter[] commandParameters);
    }
}